package com.jiazhong.basic.pack0517;

import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;
// 硬拼接方式
public class DemoD1 {
    @SneakyThrows
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入编号：");
        int id = scan.nextInt();
        System.out.print("请输入姓名：");
        String name = scan.next();
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql:///jiazhong_2025_2";
        String user = "root";
        String password = "a123456";
        Connection conn = DriverManager.getConnection(url, user, password);
        String sql = "insert into f values(" + id + ",'" + name + "')";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.executeUpdate();
        ps.close();
        conn.close();
    }
}
